<style lang="less">
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .search-info-style {
    margin: 10px;
  }
  .nopadding .ivu-table-cell {
    padding: 0px 0px;
  }
  .title {
    text-align: center;
    font-size: 1.5rem;
    padding: 20px;
  }
  .notice-name {
    line-height: 2.5;
    margin-top: 6%;
  }
  .notice-context {
    text-indent: 2em;
    line-height: 2.5;
  }
  .notice-content1 {
    padding: 0 4% 0 12%;
    position:relative;
  }
  .notice-address {
    text-align: right;
    margin-top: 10%;
  }
  .notice-date {
    text-align: right;
  }
  .text-line {
    border-color: #878787;
    border-style: solid;
    border-top-width: 0px;
    border-right-width: 0px;
    border-bottom-width: 1px;
    border-left-width: 0px;
    text-align: center;
  }
  .text-line-date {
    border-color: #878787;
    border-style: solid;
    border-top-width: 0px;
    border-right-width: 0px;
    border-bottom-width: 1px;
    border-left-width: 0px;
    width: 10%;
    text-align: center;
  }
  .text-line-address {
    border-color: #878787;
    border-style: solid;
    border-top-width: 0px;
    border-right-width: 0px;
    border-bottom-width: 1px;
    border-left-width: 0px;
    width: 15%;
    text-align: center;
  }
  .print-btn {
    padding: 15px;
    float: right;
  }
  .code-img2 {
    height: 120px;
    width: 120px;
    top: 70%;
    left: 4%;
    position: absolute;
  }
  .code-img1 {
    height: 60%;
    width: 90%;
    margin-left: 5%;
  }
  .centerimg {
    text-align: center;
  }
  .pre_img_style {
    height:500px;
    width:auto;
    max-width: 500px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
</style>
<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Tabs :animated="false" @on-click="searchData(tabInfoAll.tabIndex)" v-model="tabInfoAll.tabIndex">
      <TabPane v-for="tabInfo in tabInfoAll.list" :key="tabInfo.id" :label="tabInfo.tab_name">
        <Row class="search-info-style">
          <Col span="6">
            <span style="text-al">申请人：</span>
            <Input style="width: 70%;" v-model="searchInfo.applyname" />
          </Col>
          <Col span="6">
            <span>业务编号：</span>
            <Input style="width: 70%;" v-model="searchInfo.order_code" />
          </Col>
          <Col span="6">
            <span>申请时间：</span>
            <DatePicker type="datetimerange" format="yyyy/MM/dd" transfer="" placement="bottom-end"
                        style="width: 70%" v-model="searchInfo.applytime"></DatePicker>
          </Col>
          <Button class="new-btn-sty" @click="searchData(tabInfoAll.tabIndex)">
            <Icon type="ios-clock-outline" /> 刷新
          </Button>
          <Button class="new-btn-sty" @click="searchData(tabInfoAll.tabIndex)">
            <Icon type="ios-search" /> 搜索
          </Button>
          <Button class="new-btn-sty" @click="exportData(tabInfoAll.tabIndex)" v-if="companyCode == 'LM40002'">
            <Icon type="ios-search" /> 导出数据
          </Button>
        </Row>
        <Row class="search-info-style" v-if="companyCode == 'LM40002'">
          <Col span="6">
            <span>业务部门：</span>
            <Select v-model="searchInfo.department_name" style="width:65%">
              <Option v-for="(item,index) in departmentList" :value="item.name" :key="index">{{ item.name }}</Option>
            </Select>
          </Col>
        </Row>
        <Table border :columns="columns1" :data="datalist" >
          <template slot-scope="{ row, index }" slot="item_title">
            <span v-if="row.state == '1' || row.state == '7'">
              <Icon type="md-alarm" style="color: #19be6b"/>
            </span>
            <span>{{row.title}}</span>
          </template>
          <template slot-scope="{ row, index }" slot="time">
            <span v-if="row.state == '1' || row.state == '81'">
              <span>{{time(row.item_time)}}</span>
            </span>
            <span v-if="row.state == '2' || row.state == '3'">
              <span v-if="row.item_num==NaN">
0时0分0秒
              </span>
              <span v-else>{{times(row.item_num/60)}}</span>
            </span>
            <span v-if="row.state == '9' || row.state == '0'|| row.state == '7'|| row.state=='8'">
              <span>0时0分0秒</span>
            </span>
            <span v-if="row.state == '191' || row.state == '194' || row.state == '195'">
              <span>{{time(row.item_time)}} </span>
            </span>
            <span v-if="row.state == '192' || row.state == '193'">
             <span v-if="row.item_num==undefined">0小时</span>
              <span v-else>{{times(row.item_num)}} </span>
            </span>
          </template>
        </Table>
        <Row v-if="loadData == true">
          <Col class="demo-spin-col" span="8" offset="8">
            <Spin fix>
              <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
              <div>数据正在加载</div>
            </Spin>
          </Col>
        </Row>
        <Page class="page_style" :total="searchInfo.totalnum" :current="searchInfo.currentPageNo"
              :page-size="searchInfo.currentPageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="size"/>
      </TabPane>
    </Tabs>
    <!-- 全部模态框功能统一显示 -->
    <Modal v-model="modelShow.show" :title="modelShow.title" width="900">
      <!-- 订单进度模态框 -->
      <template v-if="processModal.show">
        <Steps :current="processModal.step_num" direction="vertical" style="margin-left: 100px;width: 70%;">
          <Step v-for="(item, index) in processModal.process_list" v-bind:key="index"
          :title="item.step_title" :content="item.text"></Step>
        </Steps>
      </template>
      <!-- 订单处理功能模态框 -->
      <template v-if="modalInfo.show">
        <Form label-position="right" :label-width="100">
          <Row>
            <Col span="5" class="ivu-form-item-label">{{modalInfo.params_name}}：</Col>
            <Col span="16" class="ivu-form-item-content">
              <Input v-if="modalInfo.params_type == 'textarea'" v-model="modalInfo.text"
              type="textarea" :autosize="{minRows: 3,maxRows: 7}" :disabled="modalInfo.update_flag"></Input>
              <Select v-if="modalInfo.params_type == 'select'" v-model="modalInfo.text" filterable>
                <Option v-for="company in company_list" :value="company.code"
                v-bind:key="company.key">{{company.sq_name }} {{company.name}}（{{company.code}}）</Option>
              </Select>
            </Col>
          </Row>
        </Form>
      </template>
      <!-- 通知单模态框 -->
      <template v-if="modal">
        <div style="background-color:white;line-height: 2.5;position:relative;width: 100%;height: 500px;" class="notice-content" id="printMe1">
          <div class="title">便民服务事项受理通知单</div>
          <div style="font-size: 1rem">
            <div class="notice-name">尊敬的 <u>{{printData.name}}</u> 先生/女士:</div>
            <div class="notice-context">您于 <u>{{printData.aa}}</u>年 <u>{{printData.bb}}</u>月
              <u>{{printData.cc}}</u>日来我社区提报的 <u>{{printData.title}}</u> 事项,我社区已经受理,状态为
              <u><span v-if="printData.state == '2'">办理完结</span></u> (办理完结;流转至其他社区;提报至业务部门)。
            </div>
            <div class="notice-address">沈阳市 <u>{{address}}</u> 社区居民委员会</div>
            <div class="notice-date">
              <u>{{printData.aa}}</u>年
              <u>{{printData.bb}}</u>月
              <u>{{printData.cc}}</u>日
            </div>
          </div>
          <div id="qrcode1" ref="qrcode1" style="position: absolute;margin-top: -12%;"></div>
        </div>
      </template>
      <!-- 要件模态框 -->
      <template v-if="modal1">
        <div style="background-color:white;line-height: 2.5;" class="" id="printMe1">
          <div style="height:auto;text-align: -webkit-center">
            <Carousel v-model="picPreviewMol.picIndex" style="width:500px" dots="outside" trigger="hover">
              <CarouselItem class="centerimg" v-for="(imginfo, index) in picPreviewMol.pic_urls" :key="index">
                <img :src="imginfo" class="pre_img_style" />
              </CarouselItem>
            </Carousel>
          </div>
        </div>
      </template>
      <!-- 电子证照图片 -->
      <template v-if="resultImg.show">
        <div class="" id="printMe1">
          <img :src="resultImg.imgs" style="width: 100%"/>
        </div>
      </template>
      <!-- 空表模态框 -->
      <template v-if="modal2">
        <Row>
          <Col span="24" id="printMe1" class="ivu-form-item-content" style="text-align: center">
            <embed width="800" height="600" :src="paramskImg"></embed>
          </Col>
        </Row>
      </template>
      <div slot="footer">
        <Button type="success" @click="acceptBtn" v-if="modalInfo.show&&!modalInfo.update_flag">确定</Button>
        <Button type="success" v-print="'#printMe1'" v-if="modal || modal1 || resultImg.show">打印</Button>
        <Button type="error" @click="modelShow.show=false">关闭</Button>
      </div>
    </Modal>
    <!-- 通知单模态框 -->
    <Modal v-model="hcpinfo.isshow" title="好差评二维码" width="300">
      <div style="background-color:white;line-height: 2.5;position:relative;width: 100%;height: 200px;" class="notice-content" id="printMe1">
          <div id="hcpqrcode" ref="hcpqrcode" style="position: absolute;margin: auto;margin-top: 10%;margin-left: 20%;width: 100%;"></div>
      </div>
    </Modal>
    <Modal v-model="mydinfo.isshow" title="满意度评价二维码" width="300">
      <div style="background-color:white;line-height: 2.5;position:relative;width: 100%;height: 200px;" class="notice-content" id="printMe1">
          <div id="mydqrcode" ref="mydqrcode" style="position: absolute;margin: auto;margin-top: 10%;margin-left: 20%;width: 100%;"></div>
      </div>
    </Modal>
    <Modal
      v-model="deleteModal"
      title="删除"
      @on-ok="deleteOk">
      是否确认删除？
    </Modal>
    <Modal
      v-model="copyModal"
      title="复制"
      @on-ok="copyOk">
      是否确认复制该订单？
    </Modal>
    <Modal
      v-model="jyzDZZZModal"
      width="700"
      height="700"
      title="就业创业证">
      <div style="width:650px"  id="printMe16">
        <img :src="urlL" style="width: 650px;height: 650px"/>
      </div>
      <div slot="footer">
        <Button type="primary" @click="jyzDZZZModal=false" >确定</Button>
        <Button type="success" v-print="'#printMe16'" >打印</Button>
      </div>
    </Modal>
    <div v-show="false">
      <Table border :columns="columns1" :data="datalist" ref="table1">
        <template slot-scope="{ row, index }" slot="item_title">
            <span v-if="row.state == '1' || row.state == '7'">
              <Icon type="md-alarm" style="color: #19be6b"/>
            </span>
          <span>{{row.title}}</span>
        </template>
        <template slot-scope="{ row, index }" slot="time">
            <span v-if="row.state == '1' || row.state == '81'">
              <span>{{time(row.item_time)}} 小时</span>
            </span>
          <span v-if="row.state == '2' || row.state == '3'">
             <span v-if="row.item_num==undefined">0小时</span>
              <span v-else>{{times(row.item_num)}} 小时</span>
            </span>
          <span v-if="row.state == '9' || row.state == '0'|| row.state == '7'|| row.state=='8'">
              <span>0时0分0秒</span>
            </span>
        </template>
      </Table>
    </div>
  </Card>

</template>
<script>
import {
  weborderlist,
  setorderapply,
  tabcount,
  date2str,
  orderProcess,
  getUserByMZList,
  getPDFByOrderCode,
  deleteOrder,
  deleteOrderAndSaveLog,
  createcopyOrderInfo,
  itemTypeList,
  getJyzDzzzUrl,
  createHcpUrl
} from '@/api/eventlist'
import ercode from '@/assets/images/ercode.jpeg'
import expandRow from './components/index'
import QRCode from 'qrcodejs2'
import qrcode2 from 'qrcode2'
import { createPost } from '@/api/post'
export default {
  name: 'workbench',
  components: {
    expandRow
  },
  data () {
    return {
      jyzAbstractcode: '',
      jyzName: '',
      jyzDZZZModal: false,
      urlL: '',
      departmentList: [],
      copyModal: false,
      copyCode: '',
      deleteModal: false,
      deleteMsg: {},
      loadData: true,
      today: new Date().getTime(),
      picPreviewMol: {
        preShow: false,
        pic_urls: [],
        picIndex: 0
      },
      hcpinfo: {
        isshow: false,
        qrcode: ''
      },
      mydinfo: {
        isshow: false,
        qrcode: ''
      },
      paramsImg: '',
      paramskImg: '',
      paramsArr: [],
      codeUrl: 'http://sjb.tripln.com/views/manage/iview_order_detail.html?code=SQ1561461755825',
      printData: {
        aa: '',
        bb: '',
        cc: ''
      },
      modelShow: { show: false, title: '' },
      modal: false,
      modal1: false,
      modal2: false,
      searchInfo: {
        applyname: '',
        order_code: '',
        applytime: [],
        totalnum: 0,
        currentPageNo: 1,
        currentPageSize: 10,
        department_name: ''
      },
      tabInfoAll: {
        tabIndex: 0,
        listIndex: { a0: 2, a1: 3, a2: 6, a3: 7, a7: 5, a8: 4, a81: 4, a82: 4, a9: 1 },
        list: [
          { id: '1', tab_name: '全部', count: 0, state: null },
          { id: '2', tab_name: '待提报', count: 0, state: '9' },
          { id: '3', tab_name: '待受理', count: 0, state: '0' },
          { id: '4', tab_name: '办理中', count: 0, state: '1' },
          { id: '5', tab_name: '转件中', count: 0, state: '8,81,82' },
          { id: '6', tab_name: '待办结', count: 0, state: '7' },
          { id: '7', tab_name: '办结成功', count: 0, state: '2' },
          { id: '8', tab_name: '办结失败', count: 0, state: '3' }
        ]
      },
      resultImg: { show: false, imgs: [] },
      processModal: { show: false, process_list: [] },
      columns1: [
        { title: '',
          type: 'expand',
          width: 40,
          align: 'center',
          render: (h, params) => {
            return h(expandRow,
              {
                props: { params: params },
                on: {
                  breachRun: (type, data) => {
                    console.log(type, 6666)
                    if (type === 1) {
                      this.viewProcess(data)
                      this.modal = false
                      this.modalInfo.show = false
                      this.modal1 = false
                      this.modal2 = false
                      this.resultImg.show = false
                    } else if (type === 2) {
                      console.log(data.code, '!!!!')
                      // 调用一个方法弹出带二维码的模态框
                      var url = 'http://sjb.tripln.com/views/manage/iview_order_detail.html?code=' + data.code
                      this.modal = true
                      this.modalInfo.show = false
                      this.modal1 = false
                      this.processModal.show = false
                      this.modal2 = false
                      this.resultImg.show = false
                      this.printData = data
                      this.printData.create_time = this.printData.create_time.substring(0, 10)
                      this.printData.aa = this.printData.create_time.substring(0, 4)
                      this.printData.bb = this.printData.create_time.substring(5, 7)
                      this.printData.cc = this.printData.create_time.substring(8, 10)
                      this.showModel(true, '便民服务事项受理通知单', url)
                    } else if (type === 3) {
                      this.popModal(data.data, data.key1, data.key2)
                      this.modal = false
                      this.modal1 = false
                      this.processModal.show = false
                      this.modal2 = false
                    } else if (type === 4) {
                      this.handlerItem(data.data, data.key1, data.key2)
                      this.modal = false
                      this.modal1 = false
                      this.processModal.show = false
                      this.modalInfo.show = false
                      this.modal2 = false
                    } else if (type === 5) {
                      this.processModal.show = false
                      this.modal = false
                      this.modal2 = false
                      this.modalInfo.show = false
                      this.resultImg.show = false
                      this.modal1 = true
                      this.paramsImg = data
                      this.picPreviewMol.picIndex = 0
                      this.picPreviewMol.pic_urls = data.split(',')
                      this.showModel(true, '要件预览打印', url)
                    } else if (type === 6) {
                      this.paramskImg = ''
                      if (data.item_id === '11210101000000MZJD5212000207000') {
                        getPDFByOrderCode({ code: data.code }).then(res => {
                          if (res.data.errcode === 0) {
                            this.paramskImg = 'data:application/pdf;base64,' + res.data.data
                            this.modal = false
                            this.modalInfo.show = false
                            this.modal1 = false
                            this.processModal.show = false
                            this.resultImg.show = false
                            this.modal2 = true
                            this.showModel(true, '打印表格')
                            this.refreshData()
                          } else {
                            this.$Notice.error({ title: '失败', desc: res.data.errmsg })
                          }
                        })
                      } else {
                        this.paramskImg = params.row.form_url
                        this.modal = false
                        this.modalInfo.show = false
                        this.modal1 = false
                        this.processModal.show = false
                        this.resultImg.show = false
                        this.modal2 = true
                        this.showModel(true, '打印表格')
                        this.refreshData()
                      }
                    } else if (type === 9) {
                      this.findJyzDzzz(data)
                    }
                  }
                }
              })
          }
        },
        {
          title: '事项名称',
          minWidth: 190,
          key: 'title',
          // slot: 'item_title'
          render: (h, params) => {
            let temp = []
            if (params.row.state === '1' || params.row.state === '7') {
              let create_time1 = new Date(params.row.create_time).getTime()
              create_time1 += 86400000 * params.row.PROMISE_DAY
              if ((create_time1 + 86400000 * 3) < this.today) {
                temp.push(h('Icon', { props: { type: 'md-alarm', size: '25' }, style: { color: '#f00' } }))
              } else if (create_time1 < this.today) {
                temp.push(h('Icon', { props: { type: 'md-alarm', size: '25' }, style: { color: '#f90' } }))
              }
            }
            temp.push(h('span', ' \xa0' + params.row.title))
            return h('div', temp)
          }
        },
        { title: '业务编号', key: 'code', width: 150 },
        { title: '申请人', key: 'name', width: 80 },
        { title: '手机号', key: 'mobile_encryption', width: 115 },
        { title: '身份证', key: 'cardno_encryption', width: 160 },
        { title: '状态', key: 'process_name', width: 85, align: 'center', className: 'nopadding' },
        { title: '申请时间', key: 'create_time', width: 140, align: 'center', className: 'nopadding' },
        { title: '办结时长', slot: 'time', width: 140, align: 'center', className: 'nopadding' },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'nopadding',
          minWidth: 130,
          render: (h, params) => {
            let temp = []
            let action1 = '{}'
            if (params.row.action) {
              action1 = JSON.parse(params.row.action)
            }
            for (let key in action1) {
              if (action1[key].type === 'button' && action1[key].next_process_id !== '-1') {
                temp.push(
                  h('Button', {
                    props: { type: 'success', size: 'small' },
                    style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                    on: {
                      click: () => {
                        // 操作类型非下划线开头时，表示功能按钮
                        if (action1[key].params_type && action1[key].params_type.indexOf('_') !== 0) {
                          this.modal = false
                          this.modal1 = false
                          this.processModal.show = false
                          this.modal2 = false
                          this.resultImg.show = false
                          this.popModal(params.row, action1[key], key)
                        } else {
                          this.modal = false
                          this.modal1 = false
                          this.processModal.show = false
                          this.modal2 = false
                          this.resultImg.show = false
                          this.handlerItem(params.row, key, action1[key])
                        }
                      }
                    }
                  }, action1[key].name)
                )
              }
            }
            // 除了草稿状态，其他都默认加上查看按钮
            if (params.row.state === '9' || params.row.state === '0') {
              temp.push(
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.updateInfo(params.row, '1')
                    }
                  }
                }, '编辑')
              )
              temp.push(
                h('Button', {
                  props: { type: 'error', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.deleteModal = true
                      this.deleteMsg = params.row
                    }
                  }
                }, '删除')
              )
              if (params.row.order_del_flag === '0') {
                temp.push(
                  h('Button', {
                    props: { type: 'error', size: 'small' },
                    style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                    on: {
                      click: () => {
                        this.deleteInfo(params.row)
                      }
                    }
                  }, '撤销')
                )
              }
            } else if (params.row.state === '3') {
              temp.push(
                h('Button', {
                  props: { type: 'error', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.copyModal = true
                      this.copyCode = params.row.code
                    }
                  }
                }, '复制')
              )
              temp.push(
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px', backgroundColor: '#235CA7', borderColor: '#235CA7' },
                  on: {
                    click: () => {
                      this.updateInfo(params.row, '2')
                    }
                  }
                }, '查看')
              )
            } else {
              temp.push(
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px', backgroundColor: '#235CA7', borderColor: '#235CA7' },
                  on: {
                    click: () => {
                      this.updateInfo(params.row, '2')
                    }
                  }
                }, '查看')
              )
            }
            if (params.row.state === '2' || params.row.state === '3') {
              temp.push(
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.hcp(params.row)
                    }
                  }
                }, '好差评'),
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', marginTop: '2px', marginBottom: '2px' },
                  on: {
                    click: () => {
                      this.myd(params.row)
                    }
                  }
                }, '满意度评价')
              )
            }
            return h('div', temp)
          }
        }
      ],
      datalist: [],
      modalInfo: {},
      company_list: [],
      ercode
    }
  },
  computed: {
    address () {
      return this.$store.state.user.severUserInfo.company_name
    },
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    findJyzDzzz (param) {
      console.log(param, 9999)
      this.getJyzCode(param)
    },
    getJyzCode (par) {
      let param = {
        apiName: 'sq4zecert',
        aac002: par.cardno
      }
      createPost(param).then(ret => {
        if (ret.data.data.result === '1') {
          this.jyzAbstractcode = ret.data.data.abstractcode
          this.jyzName = par.name
          console.log(this.searchInfo.applyname)
          if (this.jyzAbstractcode === undefined || this.jyzAbstractcode === null || this.jyzAbstractcode === '') {
            this.$Notice.error({ title: '错误', desc: '没有电子证提取码无法获取电子图片' })
          } else {
            let data = {
              cardno: param.aac002,
              document_name: 'param409',
              jyzdzzz: this.jyzAbstractcode,
              name: this.jyzName

            }
            getJyzDzzzUrl(data).then(res => {
              if (res.data.errcode === 0) {
                let url = res.data.data.url.toString().substring(0, res.data.data.url.toString().length - 1)
                let start = url.lastIndexOf(',')
                // this.jyzDzzzUrl = start.substring(start, url.length).split(',')
                this.urlL = url.substring(start + 1, url.length)
                console.log(this.urlL)
                this.jyzDZZZModal = true
              } else {
                this.$Notice.error({ title: '错误', desc: res.data.errmsg })
              }
            })
          }
        } else {
          this.$router.push({
            name: 'handinformation',
            params: { itemid: item.id, cardno: this.cardno, operation: '1' }
          })
        }
      })
    },
    exportData (type) {
      if (this.datalist.length === 0) {
        this.$Notice.warning({ title: '导出失败', desc: '无统计数据' })
        return
      }
      let fileName = ''
      if (type === 0) {
        fileName = '全部数据'
      } else if (type === 1) {
        fileName = '待提报数据'
      } else if (type === 2) {
        fileName = '待受理数据'
      } else if (type === 3) {
        fileName = '办理中数据'
      } else if (type === 4) {
        fileName = '转件中数据'
      } else if (type === 5) {
        fileName = '待办结数据'
      } else if (type === 6) {
        fileName = '办结成功数据'
      } else if (type === 7) {
        fileName = '办结失败数据'
      }
      console.log(fileName, 666)
      this.$refs.table1.exportCsv({
        filename: fileName,
        columns: this.columns1.filter((col, index) => index < 8),
        data: this.datalist.map(item => {
          item.time = (item.state === '1' || item.state === '1') ? this.time(item.item_time) : ((item.state === '2' || item.state === '3') ? this.times(item.item_num) : 0 + '小时')
          console.log(item)
          return item
        }),
        original: false
      })
    },
    hcp (row) {
      console.log(row, 'mmmmmmmmmm')
      let that = this
      let params = {
        order_code: row.code
      }
      createHcpUrl(params).then(res => {
        if (res.data.errcode === 0) {
          this.hcpinfo.isshow = true
          let url = res.data.data.returl
          document.getElementById('hcpqrcode').innerHTML = '正在加载，请稍候...'
          setTimeout(function () {
            that.getHcpCode(url)
          }, 1000)
        } else {
          this.$Notice.error({ title: '', desc: res.data.errmsg })
        }
      })
    },
    getHcpCode (codeUrl) {
      document.getElementById('hcpqrcode').innerHTML = ''
      var qrcode = new QRCode(document.getElementById('hcpqrcode'), {
        text: codeUrl,
        top: 0,
        width: 150,
        height: 150,
        colorDark: '#000000',
        colorLight: '#ffffff',
        correctLevel: qrcode2.CorrectLevel.H
      })
      console.log(qrcode, 'hcpqrcode')
    },
    myd (row) {
      console.log(row, 'mmmmmmmmmm')
      let that = this
      this.mydinfo.isshow = true
      let url = 'http://qstb.mzj.shenyang.gov.cn/mzmobile/#/quanshitongban/auditorderevaluate?order_code=' + row.code
      // + '&iscs=true'
      document.getElementById('mydqrcode').innerHTML = '正在加载，请稍候...'
      setTimeout(function () {
        that.getMydCode(url)
      }, 1000)
    },
    getMydCode (codeUrl) {
      document.getElementById('mydqrcode').innerHTML = ''
      var qrcode = new QRCode(document.getElementById('mydqrcode'), {
        text: codeUrl,
        top: 0,
        width: 150,
        height: 150,
        colorDark: '#000000',
        colorLight: '#ffffff',
        correctLevel: qrcode2.CorrectLevel.H
      })
      console.log(qrcode, 'mydqrcode')
    },
    size (pageSize) {
      this.searchInfo.currentPageSize = pageSize
      this.changePageNo()
    },
    copyOk () {
      console.log(this.copyCode)
      let data = {
        code: this.copyCode
      }
      createcopyOrderInfo(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({ title: '复制成功', desc: '新的业务编号：' + ret.data.data.code })
          this.tabInfoAll.tabIndex = 0
          this.init({ state: null })
        } else {
          this.$Notice.error({ title: '复制失败', desc: ret.data.errmsg })
        }
      })
    },
    // times (date) {
    //   if (date === undefined || date === null || date === '') {
    //     return '0时0分0秒'
    //   }
    //   if (date < 0) {
    //     return '0时0分0秒'
    //   }
    //   let time = date * 60
    //   let min = Math.floor(time % 3600)
    //   return Math.floor(time / 3600) + '时' + Math.floor(min / 60) + '分' + Math.floor(time / 60) + '秒'
    // //  return date.toString().substring(0, 3)
    // },
    times (date) {
      if (date === undefined || date === null || date === '') {
        return '0时0分0秒'
      }
      let staytimeGap = date
      if (staytimeGap < 0) {
        return '0时0分0秒'
      }
      let stayHour = Math.floor(staytimeGap / (3600 * 1))
      let leave1 = staytimeGap % (3600 * 1)
      let stayMin = Math.floor(leave1 / (60 * 1))
      let leave2 = leave1 % (60 * 1)
      let staySec = Math.floor(leave2 / 1)
      return stayHour + '时' + stayMin + '分' + staySec + '秒'
    },
    time (date) {
      if (date === undefined || date === null || date === '') {
        return '0时0分0秒'
      }
      let timestamp1 = new Date(date).getTime()
      let timestamp2 = new Date().getTime()
      let staytimeGap = timestamp2 - timestamp1
      if (staytimeGap < 0) {
        return '0时0分0秒'
      }
      let stayHour = Math.floor(staytimeGap / (3600 * 1000))
      let leave1 = staytimeGap % (3600 * 1000)
      let stayMin = Math.floor(leave1 / (60 * 1000))
      let leave2 = leave1 % (60 * 1000)
      let staySec = Math.floor(leave2 / 1000)
      // if (staySec.toString().length > 2) {
      //   staySec = staySec.substring(0, 2)
      // }
      return stayHour + '时' + stayMin + '分' + staySec + '秒'
    },
    deleteOk () {
      // console.log(row.code)
      let data = {
        code: this.deleteMsg.code
      }
      console.log(data)
      deleteOrderAndSaveLog(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.init({ 'state': this.tabInfoAll.list[this.tabInfoAll.tabIndex].state })
        } else {
          this.$Notice.error({ title: '删除失败', desc: ret.data.errmsg })
        }
      })
    },
    // 查询订单列表接口
    init (param) {
      param.pageNo = this.searchInfo.currentPageNo
      param.pageSize = this.searchInfo.currentPageSize
      weborderlist(param).then(res => {
        if (res.data.data) {
          this.datalist = res.data.data.results
          this.searchInfo.totalnum = res.data.data.totalRecord
          let that = this
          this.datalist.forEach(function (temp1, index) {
            temp1._expanded = false
            if (temp1.mobile) {
              if (temp1.mobile.length === 8 || temp1.mobile.length === 7) {
                temp1.mobile_encryption = temp1.mobile.substring(0, 3) + '****' + temp1.mobile.substring(6)
              } else if (temp1.mobile.length === 11) {
                temp1.mobile_encryption = temp1.mobile.substring(0, 3) + '****' + temp1.mobile.substring(7)
              } else {
                temp1.mobile_encryption = temp1.mobile
              }
            }
            if (temp1.cardno) {
              temp1.cardno_encryption = temp1.cardno.substring(0, 6) + '********' + temp1.cardno.substring(14)
            }
            if (temp1.state === '1' || temp1.state === '7') {
              console.log(temp1.PROMISE_DAY, 'PROMISE_DAY')
              // 距离订单超时的时间差 = 订单理论结束时间 - 当前时间
              let timediff = temp1.createtimestamp + 86400000 * temp1.PROMISE_DAY - that.today
              console.log(timediff, 'timediff')
              if (timediff < 0) {
                temp1.timeout = 3
              }
            }
          })
          this.loadData = false
        } else {
          this.loadData = true
          this.$Notice.error({ title: '获取事项办理列表失败', desc: res.data.errmsg })
        }
      })
    },
    // 统计每个标签页的事项数
    initTabCount () {
      tabcount().then(res => {
        if (res.data.data) {
          this.tabInfoAll.list[0].count = 0
          this.tabInfoAll.list[1].count = 0
          this.tabInfoAll.list[2].count = 0
          this.tabInfoAll.list[3].count = 0
          this.tabInfoAll.list[4].count = 0
          this.tabInfoAll.list[5].count = 0
          this.tabInfoAll.list[6].count = 0
          this.tabInfoAll.list[7].count = 0
          res.data.data.forEach(element => {
            let index = this.tabInfoAll.listIndex['a' + element.state]
            if (index || index === 0) {
              this.tabInfoAll.list[0].count += element.num
              this.tabInfoAll.list[index].count += element.num
            }
          })
          this.$forceUpdate()
        }
      })
    },
    // 切换tab页和搜索，刷新按钮
    searchData (tabIndex) {
      let params = {
        name: this.searchInfo.applyname,
        code: this.searchInfo.order_code,
        state: this.tabInfoAll.list[tabIndex].state,
        department_name: this.searchInfo.department_name
      }
      if (this.searchInfo.applytime[0]) params.start_time = date2str(this.searchInfo.applytime[0])
      if (this.searchInfo.applytime[1]) params.end_time = date2str(this.searchInfo.applytime[1])
      this.searchInfo.currentPageNo = 1
      this.init(params)
    },
    // 切换页码
    changePageNo (pageNo) {
      console.log(pageNo)
      this.searchInfo.currentPageNo = pageNo
      let params = {
        name: this.searchInfo.applyname,
        state: this.tabInfoAll.list[this.tabInfoAll.tabIndex].state
      }
      if (this.searchInfo.applytime[0]) params.start_time = date2str(this.searchInfo.applytime[0])
      if (this.searchInfo.applytime[1]) params.end_time = date2str(this.searchInfo.applytime[1])
      this.init(params)
    },
    deleteInfo (obj) {
      this.$Modal.confirm({
        title: '撤销后信息将无法找回，确认撤销当前事项！',
        onOk: () => {
          deleteOrder(obj.code).then(res => {
            if (res.data.data) {
              this.init({ 'state': this.tabInfoAll.list[this.tabInfoAll.tabIndex].state })
              this.initTabCount()
            } else {
              this.$Notice.error({ title: '失败', desc: res.data.errmsg })
            }
          })
        }
      })
    },
    viewProcess (item) {
      this.processModal.show = true
      this.processModal.title = item.title + '—办理进度'
      this.showModel(true, this.processModal.title)
      orderProcess({ order_code: item.code }).then(res => {
        if (res.data.data) {
          this.processModal.process_list = []
          res.data.data.forEach(element => {
            let temp = {}
            temp.step_title = element.process_name + '  ' + element.create_time
            if (element.status === '0') {
              temp.text = '未处理'
              if (element.process_id === '8') {
                temp.text += '（接收社区：' + element.accept_company_name + '）'
              }
            } else {
              if (element.handle_by === 'system') {
                temp.text = '操作人：' + element.handle_byname + ';' + '用时：' + element.used_time
              } else {
                if (element.handle_byname.indexOf('-') !== -1) {
                  temp.text = '操作人：' + element.handle_byname + ';' + '用时：' + element.used_time
                } else {
                  if (element.params && element.params.indexOf('_10_') !== -1) {
                    var process_params = element.params.replace('_10_', ':')
                    temp.text = '操作人：' + element.accept_company_name + '-' + element.handle_byname + ';' + process_params + ';' + '用时：' + element.used_time
                  } else if (element.params && element.params.indexOf('_10_') === -1) {
                    temp.text = '操作人：' + element.accept_company_name + '-' + element.handle_byname + ';' + element.params + ';' + '用时：' + element.used_time
                  } else {
                    temp.text = '操作人：' + element.accept_company_name + '-' + element.handle_byname + ';' + '用时：' + element.used_time
                  }
                }
              }
            }
            this.processModal.process_list.push(temp)
          })
          this.processModal.step_num = this.processModal.process_list.length
          if (res.data.data[res.data.data.length - 1].state === '1') {
            this.processModal.step_num += 1
          }
        } else {
          this.$Notice.error({ title: '失败', desc: '未知原因查询失败，请重试' })
        }
      })
    },
    // 修改订单operation=1|查看订单operation=2
    updateInfo (item, operation) {
      if (item.code !== 'SQ1598237931558' && (item.item_id === '11210101000000MZJD5212000330000' || item.item_id === '11210101000000MZJD5212000351000')) {
        this.$router.push({
          name: 'subsistenceapplication',
          params: { cardno: item.cardno, code: item.code, operation: operation, itemid: item.item_id, order_state: item.state }
        })
      } else if (item.item_id === '11210101000000MZJD5212000322000') {
        this.$router.push({
          name: 'tk_subsistenceapplication',
          params: { cardno: item.cardno, code: item.code, operation: operation, itemid: item.item_id, state: item.state }
        })
      } else if (item.item_id.indexOf('11210101000000FCJD') === 0) {
        this.$router.push({
          name: 'house_handinformation',
          params: {
            itemid: item.item_id,
            cardno: item.cardno,
            code: item.code,
            name: item.name,
            cur_data: { tabindex: this.tabInfoAll.tabIndex, pageNo: this.currentPageNo },
            operation: operation
          }
        })
      } else if (item.code === 'SQ1598237931558') {
        this.$router.push({
          name: 'db_subsistenceapplication',
          params: {
            itemid: item.item_id,
            cardno: item.cardno,
            code: item.code,
            name: item.name,
            order_state: item.state,
            cur_data: { tabindex: this.tabInfoAll.tabIndex, pageNo: this.currentPageNo },
            operation: operation
          }
        })
      } else {
        this.$router.push({
          name: 'handinformation',
          params: {
            itemid: item.item_id,
            cardno: item.cardno,
            code: item.code,
            name: item.name,
            cur_data: { tabindex: this.tabInfoAll.tabIndex, pageNo: this.currentPageNo },
            operation: operation,
            state: item.state
          }
        })
      }
    },
    // 处理事项 提报|受理|...
    handlerItem (item, key, action) {
      if (action.next_process_id === '-1') {
        this.resultImg.imgs = item.img_url
        console.log(this.resultImg.imgs, 'this.resultImg.imgs')
        this.resultImg.show = true
        this.showModel(true, '', '')
      } else if (action.next_process_id === '-3') {
        this.$router.push({
          name: 'handinformation',
          params: {
            itemid: item.item_id,
            cardno: item.cardno,
            code: item.code,
            cur_data: { tabindex: this.tabInfoAll.tabIndex, pageNo: this.currentPageNo },
            operation: '0'
          }
        })
      } else {
        this.$Modal.confirm({
          title: '确认' + action.name + '当前事项！',
          onOk: () => {
            let aaa = { code: item.code, key: key, state: item.state }
            setorderapply(aaa).then(res => {
              if (res.data.data) {
                this.init({ 'state': this.tabInfoAll.list[this.tabInfoAll.tabIndex].state })
                this.initTabCount()
              } else {
                this.$Notice.error({ title: '状态修改失败', desc: res.data.errmsg })
              }
            })
          }
        })
      }
    },
    // 弹出框功能，流程中需要填写信息的按钮
    popModal (item, modal, key) {
      this.modalInfo = {
        show: true,
        process_id: item.state,
        key: key,
        code: item.code,
        title: item.title + '-' + modal.name,
        params_type: modal.params_type,
        params_code: modal.params_code,
        next_process_id: modal.next_process_id,
        params_name: modal.params_name,
        text: modal.next_process_id === '-2' ? item.reason : '',
        update_flag: modal.next_process_id === '-2'
      }
      this.showModel(true, this.modalInfo.title)
    },
    // 弹出框功能，填写信息后确定按钮
    acceptBtn () {
      let aaa = {
        code: this.modalInfo.code,
        key: this.modalInfo.key,
        state: this.modalInfo.process_id
      }
      if (this.modalInfo.params_code.indexOf('_') === 0) {
        aaa[this.modalInfo.params_code.substring(1)] = this.modalInfo.text
      } else {
        let params = {
          params_type: this.modalInfo.params_type,
          params_name: this.modalInfo.params_name,
          params_code: this.modalInfo.params_code,
          text: this.modalInfo.text
        }
        aaa.params = JSON.stringify(params)
      }
      setorderapply(aaa).then(res => {
        if (res.data.data) {
          this.modelShow.show = false
          this.modalInfo.show = false
          this.init({ 'state': this.tabInfoAll.list[this.tabInfoAll.tabIndex].state })
          this.initTabCount()
        } else {
          this.$Notice.error({ title: '获取事项列表失败', desc: res.data.errmsg })
        }
      })
    },
    showModel (status, title, url) {
      this.modelShow = { show: status, title: title }
      if (url) {
        this.showErcode(url)
      }
    },
    // 获取收受分离的社区列表
    getColumnsList () {
      getUserByMZList().then(res => {
        if (res.data.errcode === 0) {
          this.company_list = res.data.data
        } else {
          this.$Notice.error({ title: '', desc: res.data.errmsg })
        }
      })
    },
    // 刷新pdf模态框使用，不知道为什么这样就好用，也不敢问
    refreshData () {
      this.modal2 = false
      this.$nextTick(() => {
        this.modal2 = true
      })
    },
    showErcode (codeUrl) {
      let _this = this
      console.log(codeUrl)
      setTimeout(function () {
        _this.getCode(codeUrl)
      }, 1000)
    },
    getCode (codeUrl) {
      document.getElementById('qrcode1').innerHTML = ''
      var qrcode = new QRCode(document.getElementById('qrcode1'), {
        text: codeUrl,
        top: 0,
        width: 150,
        height: 150,
        colorDark: '#000000',
        colorLight: '#ffffff',
        correctLevel: QRCode.CorrectLevel.H
      })
      console.log(qrcode, 'qrcode')
    },
    itemTypeList () {
      let data = {
        show_state: 'pc%'
      }
      itemTypeList(data).then(ret => {
        this.departmentList = ret.data.data
      })
    }
  },
  mounted () {
    // console.log(this.$route.params, '111')
    this.tabInfoAll.tabIndex = this.$route.params.tabindex || 0
    this.searchInfo.currentPageNo = this.$route.params.pageNo || 1
    this.init({ 'state': null })
    this.initTabCount()
    this.getColumnsList()
    this.itemTypeList()
  }
}
</script>
